<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category MyStockController.php
 * @Depiction
 * @Author hwy <429208948@qq.com>
 * @Date 2022/4/24  16:50
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Admin\V1;


use App\Services\MyStockService;
use Illuminate\Http\Request;

class MyStockController extends Controller
{
    protected $myStockService;

    public function __construct(MyStockService $myStockService)
    {
        $this->myStockService = $myStockService;
    }

    public function index(Request $request)
    {
        $rules      = [
            'page'  => ['nullable', 'numeric', 'gte:0'],
            'limit' => ['nullable', 'numeric', 'gte:1', 'lte:100'],
            'sort'  => ['nullable',],
            'order' => ['nullable', 'string'],
            'title' => ['nullable', 'string'],
        ];
        $attributes = [
            'page'  => '页数',
            'limit' => '每页条数',
            'sort'  => '排序字段',
            'order' => '排序顺序',
            'title' => '标题',
        ];
        $messages   = [];
        
        $validated = $this->validate($request, $rules, $messages, $attributes);

        $data = $this->myStockService->getList($validated);

        return $this->responseSuccessData('请求成功！', $data);
    }

    public function create(Request $request)
    {
        $rules      = [
            // 'name'       => ['required', 'string', 'between:2,60'],
            // 'guard_name' => ['required', 'string', 'between:2,60', Rule::in(['api', 'admin']),],
        ];
        $attributes = [
            'name'       => '角色标识',
            'guard_name' => '对应规则',
        ];
        $messages   = [
            'name.required'       => ':attribute不能为空',
            'name.string'         => ':attribute必须为字符串',
            'guard_name.required' => ':attribute不能为空',
            'guard_name.string'   => ':attribute必须为字符串',
        ];
        $validated  = $this->validate($request, $rules, $messages, $attributes);

        $this->myStockService->addData($validated);
    }

}
